/**
 * Jaxson ajax
 *
 * Copyright Remedy Interactive, licensed under Apache version 2 license:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0.html
 *
 * This notice must remain in all java source files.
 */

package org.jaxson.struts.reverseAjax;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import flexjson.JSON;


/**
 * A logical batch of events to be pushed to a client via Reverse Ajax.
 * 
 * @author Joe Maisel
 */
public class ReverseAjaxBatch implements Serializable
{
	private List<ReverseAjaxEvent> events = new ArrayList<ReverseAjaxEvent>();
	private boolean committed;

	/**
	 * @return the events
	 */
	@JSON
	public List<ReverseAjaxEvent> getEvents()
	{
		return events;
	}

	/**
	 * @param events
	 *            the events to set
	 */
	public void setEvents( List<ReverseAjaxEvent> events )
	{
		this.events = events;
	}

	/**
	 * Add an event to the current batch
	 * 
	 * @param event
	 */
	public void addEvent( ReverseAjaxEvent event )
	{
		this.events.add( event );
	}

	/**
	 * @return the committed
	 */
	@JSON(include = false)
	public boolean isCommitted()
	{
		return committed;
	}

	/**
	 * @param committed
	 *            the committed to set
	 */
	public void setCommitted( boolean committed )
	{
		this.committed = committed;
	}

	public String toString()
	{
		return super.toString() + ": " + events.toString();
	}

	private static final long serialVersionUID = 938764547573L;
}
